<template>
  <div class="elm-edit">
  <elm-page-bb>
    <el-form ref="model" :model="model" size="small" label-width="80px">
      <elm-row>
        <el-form-item label="名称" prop="name" :rules="[{ required: true, message: '必须填写'}]">
          <el-input v-model="model.name"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="model.email"></el-input>
        </el-form-item>
      </elm-row>
      <el-form-item label="电话" prop="phone">
        <el-input v-model="model.phone"></el-input>
      </el-form-item>
      <elm-row>
        <el-form-item label="传真号码" prop="czhm">
          <el-input v-model="model.czhm"></el-input>
        </el-form-item>
        <el-form-item label="网址" prop="gswz">
          <el-input v-model="model.gswz"></el-input>
        </el-form-item>
      </elm-row>
      <el-form-item label="地址" prop="gsdz">
        <el-input  type="textarea" :rows="2" v-model="model.gsdz"></el-input>
      </el-form-item>
      <elm-row>
        <el-form-item label="行业" prop="khhy">
          <elm-code dict_type="crm_customer_hy" v-model="model.khhy"></elm-code>
        </el-form-item>
        <el-form-item label="级别" prop="khjb">
          <elm-code dict_type="crm_customer_jb" v-model="model.khjb"></elm-code>
        </el-form-item>
      </elm-row>
      <elm-row>
        <el-form-item label="来源" prop="khly">
          <el-input v-model="model.khly"></el-input>
        </el-form-item>
        <el-form-item label="维系人" prop="fzxs">
          <elm-ei v-model="model.fzxs" disabled></elm-ei>
        </el-form-item>
      </elm-row>
      <el-form-item label="开票信息" prop="kpxx">
        <el-input  type="textarea" :rows="2" v-model="model.kpxx"></el-input>
      </el-form-item>
      <el-form-item label="客户喜好" prop="khxh">
        <el-input  type="textarea" :rows="2" v-model="model.khxh"></el-input>
      </el-form-item>
      <el-form-item label="资料">
        <elm-upload module_name="biz_crm_customer_file" :rel_id="model.id" :multiple="true" :limit="10"  list-type="picture" tip=" "></elm-upload>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input type="textarea" :rows="2" v-model="model.remark"></el-input>
      </el-form-item>
    </el-form>
    <el-card style="min-height: 140px;"  shadow="hover">
      <div slot="header">
        <span>联系人信息</span>
      </div>
      <el-form ref="model" :model="model" size="small" label-width="80px">
        <elm-row>
          <el-form-item label="姓名" prop="lxr_xm">
            <el-input v-model="model.lxr_xm"></el-input>
          </el-form-item>
          <el-form-item label="职务" prop="lxr_zw">
            <el-input v-model="model.lxr_zw"></el-input>
          </el-form-item>
        </elm-row>
        <elm-row>
          <el-form-item label="电话" prop="lxr_dh">
            <el-input v-model="model.lxr_dh"></el-input>
          </el-form-item>
          <el-form-item label="邮箱" prop="lxr_yx">
            <el-input v-model="model.lxr_yx"></el-input>
          </el-form-item>
        </elm-row>
      </el-form>
    </el-card>
    <template #bottom>
      <el-button type="success" size="small" @click="submit">立即保存</el-button>
      <el-button size="small" @click="close">取消</el-button>
    </template>
  </elm-page-bb>
  </div>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      model: {id: elm.newGuid(),fzxs:null},
    }
  },
  async created() {
    this.model.fzxs= await this.get_user_ei();
  },
  methods: {

    async submit() {
      await this.$refs["model"].validate();
        var res = await elm.post('/business/my/business/UpsertCustomer', this.model);
        if (res == true) {
          this.v('保存成功。')
          this.close();
            this.request.callVue.tablebinding();
        }
        else {
          this.error('保存失败，请稍后尝试。');
        }
    },
    async get_user_ei(){
      var res = await elm.post('/system/login/GetUserEi');
      //console.log(res);
      if(res.length>0)
        return res[0].emp_code;
      else
        return "";
    },
  }
}
</script>